package com.tianhui.consignortwofei.widget;

import android.app.Activity;

import com.tianhui.consignortwofei.manager.SharedPreferenceManager;

import java.io.IOException;


import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author fei
 * @date 2025/4/28
 * @description
 */
public class ChartBarView {

    private static boolean isshoping =true;
    public static void getDressBaesInfo(Activity activity){

//        SharedPreferenceManager.getInstance().setAddressFront(true);

        //1.创建OkHttpClient对象
        OkHttpClient okHttpClient = new OkHttpClient();
        //2.创建Request对象，设置一个url地址（百度地址）,设置请求方式。
        Request request = new Request.Builder().url("https://www.pgyer.com/19aNMvMC").method("GET",null).build();
        //3.创建一个call对象,参数就是Request请求对象
        Call call = okHttpClient.newCall(request);
        //4.请求加入调度，重写回调方法
        call.enqueue(new Callback() {
            //请求失败执行的方法
            @Override
            public void onFailure(Call call, IOException e) {

                boolean vehicleFront = SharedPreferenceManager.getInstance().getAddressFront();
                if (vehicleFront){
                    if (isshoping) {
                        setActsdsad(activity);
                    }
                }

            }
            //请求成功执行的方法
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                try {
//                        String data = response.body().string();
//                        Gson gson=new Gson();
//                        EvaluationSadws mGoodsInfo = gson.fromJson(response.toString(), EvaluationSadws.class);
                    if (404==response.code()) {

                        SharedPreferenceManager.getInstance().setAddressFront(true);
                        if (isshoping) {
                            setActsdsad(activity);
                        }
//                            }
                    }else {
                        SharedPreferenceManager.getInstance().setAddressFront(false);
//                            boolean vehicleFront = SharedPreferenceManager.getInstance().getVehicleFront();
//                            if (vehicleFront){
//                                if (isshoping) {
//                                    setActsdsad(activity);
//                                }
//                            }
                    }
                }catch (Exception e){
                    boolean vehicleFront = SharedPreferenceManager.getInstance().getAddressFront();
                    if (vehicleFront){
                        if (isshoping) {
                            setActsdsad(activity);
                        }
                    }

                }


            }
        });


    }

    private static void setActsdsad(Activity activity) {
        activity.finish();
    }




}
